/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package elementsDefense.enemies;

import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.AbstractControl;
import com.jme3.scene.control.Control;
import elementsDefense.Main;
import elementsDefense.map.Map.Dir;
import elementsDefense.map.Tile;

/**
 *
 * @author Ricardo
 */
public class HoverControl extends AbstractControl{

    private static final float[] steps = new float[100];
    static{
        for (int i = 0; i < steps.length; i++) {
            steps[i]=(float) Math.sin((double)i/100*(2*Math.PI));
        }
    }

    float height,varHeight,stepTime;
    public HoverControl(float height, float varHeight,float stepTime) {
        this.height = height;
        this.varHeight = varHeight;
        this.stepTime = stepTime;
    }
    
    
    int currentStep;
    @Override
    protected void controlUpdate(float tpf) {
        Vector3f tmp = spatial.getLocalTranslation();
        spatial.setLocalTranslation(tmp.x, height+varHeight*steps[currentStep], tmp.z);
        currentStep+=1;
        if(currentStep>=100) currentStep=0;
    }

    @Override
    protected void controlRender(RenderManager rm, ViewPort vp) {
    }

    public Control cloneForSpatial(Spatial spatial) {
        final HoverControl control = new HoverControl(height, varHeight, stepTime);
        /* Optional: use setters to copy userdata into the cloned control */
        // control.setIndex(i); // example
        control.setSpatial(spatial);
        return control;
    }
}
